import { RouterType } from '../../../constants/router';

/** 生成路由类型下拉可选数据 */
export function generateRouterTypeSelectorData() {
  return Object.values(RouterType).map(type => {
    return { value: type, label: getRouterTypeDisplay(type) };
  });
}

/**
 * 获取路由类型显示信息
 * @param {string} router
 */
export function getRouterTypeDisplay(router) {
  switch (router) {
    case RouterType.Unicast:
      return '单播';
    case RouterType.Broadcast:
      return '广播';
    case RouterType.Multicast:
      return '多播';
    default:
      '';
  }
}

/**
 * 校验表单是否合法
 * @param {object} form
 */
export function validateForm(form) {
  if (!form.type) return '请输入路由规则类型';
  if (!form.name) return '请输入路由规则名称';
}

const ActiveList = {
  activeTrue: true,
  activeFalse: false
};

export function getActiveSelector() {
  const result = [];
  Object.values(ActiveList).forEach(active => {
    result.push({ value: active, label: getActiveDisplay(active) });
  });
  return result;
}

export function getActiveDisplay(active) {
  switch (active) {
    case ActiveList.activeTrue:
      return '启用';
    case ActiveList.activeFalse:
      return '不启用';
    default:
      return '未知';
  }
}
